home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / jpsrc2.zip / JQUANT2.C < prev    next >
C/C++ Source or Header  |  1991-10-03  |  4KB  |  123 lines

  1. /*
  2.  * jquant2.c
  3.  *
  4.  * Copyright (C) 1991, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains 2-pass color quantization (color mapping) routines.
  9.  * These routines are invoked via the methods color_quant_prescan,
  10.  * color_quant_doit, and color_quant_init/term.
  11.  */
  12.  
  13. #include "jinclude.h"
  14.  
  15. #ifdef QUANT_2PASS_SUPPORTED
  16.  
  17.  
  18. /*
  19.  * Initialize for two-pass color quantization.
  20.  */
  21.  
  22. METHODDEF void
  23. color_quant_init (decompress_info_ptr cinfo)
  24. {
  25.   TRACEMS(cinfo->emethods, 1, "color_quant_init 2 pass");
  26. }
  27.  
  28.  
  29. /*
  30.  * Prescan some rows of pixels.
  31.  * Note: this could change the data being written into the big image array,
  32.  * if there were any benefit to doing so.  The doit routine is not allowed
  33.  * to modify the big image array, because the memory manager is not required
  34.  * to support multiple write passes on a big image.
  35.  */
  36.  
  37. METHODDEF void
  38. color_quant_prescan (decompress_info_ptr cinfo, int num_rows,
  39.              JSAMPIMAGE image_data)
  40. {
  41.   TRACEMS1(cinfo->emethods, 2, "color_quant_prescan %d rows", num_rows);
  42. }
  43.  
  44.  
  45. /*
  46.  * This routine makes the final pass over the image data.
  47.  * output_workspace is a one-component array of pixel dimensions at least
  48.  * as large as the input image strip; it can be used to hold the converted
  49.  * pixels' colormap indexes.
  50.  */
  51.  
  52. METHODDEF void
  53. final_pass (decompress_info_ptr cinfo, int num_rows,
  54.         JSAMPIMAGE image_data, JSAMPARRAY output_workspace)
  55. {
  56.   TRACEMS1(cinfo->emethods, 2, "final_pass %d rows", num_rows);
  57.   /* for debug purposes, just emit input data */
  58.   /* NB: this only works for PPM output */
  59.   (*cinfo->methods->put_pixel_rows) (cinfo, num_rows, image_data);
  60. }
  61.  
  62.  
  63. /*
  64.  * Perform two-pass quantization: rescan the image data and output the
  65.  * converted data via put_color_map and put_pixel_rows.
  66.  * The source_method is a routine that can scan the image data; it can
  67.  * be called as many times as desired.  The processing routine called by
  68.  * source_method has the same interface as color_quantize does in the
  69.  * one-pass case, except it must call put_pixel_rows itself.  (This allows
  70.  * me to use multiple passes in which earlier passes don't output anything.)
  71.  */
  72.  
  73. METHODDEF void
  74. color_quant_doit (decompress_info_ptr cinfo, quantize_caller_ptr source_method)
  75. {
  76.   TRACEMS(cinfo->emethods, 1, "color_quant_doit 2 pass");
  77.   (*source_method) (cinfo, final_pass);
  78. }
  79.  
  80.  
  81. /*
  82.  * Finish up at the end of the file.
  83.  */
  84.  
  85. METHODDEF void
  86. color_quant_term (decompress_info_ptr cinfo)
  87. {
  88.   TRACEMS(cinfo->emethods, 1, "color_quant_term 2 pass");
  89. }
  90.  
  91.  
  92. /*
  93.  * Map some rows of pixels to the output colormapped representation.
  94.  * Not used in two-pass case.
  95.  */
  96.  
  97. METHODDEF void
  98. color_quantize (decompress_info_ptr cinfo, int num_rows,
  99.         JSAMPIMAGE input_data, JSAMPARRAY output_data)
  100. {
  101.   ERREXIT(cinfo->emethods, "Should not get here!");
  102. }
  103.  
  104.  
  105. /*
  106.  * The method selection routine for 2-pass color quantization.
  107.  */
  108.  
  109. GLOBAL void
  110. jsel2quantize (decompress_info_ptr cinfo)
  111. {
  112.   if (cinfo->two_pass_quantize) {
  113.     /* just one alternative for the moment */
  114.     cinfo->methods->color_quant_init = color_quant_init;
  115.     cinfo->methods->color_quant_prescan = color_quant_prescan;
  116.     cinfo->methods->color_quant_doit = color_quant_doit;
  117.     cinfo->methods->color_quant_term = color_quant_term;
  118.     cinfo->methods->color_quantize = color_quantize;
  119.   }
  120. }
  121.  
  122. #endif /* QUANT_2PASS_SUPPORTED */
  123.